<?php

/****************************************
*** mysql-rw-php version 0.1 @ 2009-4-16
*** code by hqlulu#gmail.com
*** http://www.aslibra.com
*** http://code.google.com/p/mysql-rw-php/
*** code modify from class_mysql.php (uchome)
****************************************/

require_once('scripts/mysql_rw_php.class.php');

//rw info
$db_rw = array(
	'dbhost'=>'localhost',
	'dbuser'=>'master',
	'dbpw'=>'111',
	'dbname'=>'adtree'
);

$db_ro = array(
	array(
		'dbhost'=>'localhost',
		'dbuser'=>'test',
		'dbpw'=>'123'
	)
);

$DB = new mysql_rw_php;

//connect Master
$DB->connect($db_rw[dbhost], $db_rw[dbuser], $db_rw[dbpw], $db_rw[dbname]);

//Method 1: connect one server
$DB->connect_ro($db_ro[0][dbhost], $db_ro[0][dbuser], $db_ro[0][dbpw]);

//Method 2: connect one server from a list by rand
$DB->set_ro_list($db_ro);

//send to rw
//$sql = "INSERT INTO content (typ, url) SELECT 'aaa','advertising3' FROM dual WHERE not exists (select id from content where content.url = 'advertising3');";
//$DB->query($sql);
//echo $DB->insert_id();
//send to ro
$sql = "select * from content";
$qr = $DB->query($sql);
while($row = $DB->fetch_array($qr)){
	echo $row['id'].$row['typ'].$row['url'].'<br>';
}
?>